using System;
using System.ComponentModel.DataAnnotations;
using Terra.Core.Common.Enums.Logging;
using Terra.Core.Common.Models.Pagination;

namespace Terra.Data.Models.Loggings;

/// <summary>
/// 异常日志查询模型
/// </summary>
public class ExceptionQueryDto : PagedRequest
{
    /// <summary>
    /// 开始时间
    /// </summary>
    public DateTime? StartTime { get; set; }

    /// <summary>
    /// 结束时间
    /// </summary>
    public DateTime? EndTime { get; set; }

    /// <summary>
    /// 异常类型
    /// </summary>
    [MaxLength(256)]
    public string ExceptionType { get; set; }

    /// <summary>
    /// 异常严重程度
    /// </summary>
    public ExceptionSeverity? Severity { get; set; }

    /// <summary>
    /// 请求路径
    /// </summary>
    [MaxLength(256)]
    public string RequestPath { get; set; }

    /// <summary>
    /// 跟踪ID
    /// </summary>
    [MaxLength(100)]
    public string TraceId { get; set; }

    /// <summary>
    /// 异常消息(模糊查询)
    /// </summary>
    public string ExceptionMessage { get; set; }

    /// <summary>
    /// IP地址
    /// </summary>
    public string IpAddress { get; set; }
}

/// <summary>
/// 异常日志列表项模型
/// </summary>
public class ExceptionItemDto
{
    /// <summary>
    /// 异常日志ID
    /// </summary>
    public Guid Id { get; set; }

    /// <summary>
    /// 异常类型
    /// </summary>
    public string ExceptionType { get; set; }

    /// <summary>
    /// 异常消息
    /// </summary>
    public string ExceptionMessage { get; set; }

    /// <summary>
    /// 异常时间
    /// </summary>
    public DateTime ExceptionTime { get; set; }

    /// <summary>
    /// 请求路径
    /// </summary>
    public string RequestPath { get; set; }

    /// <summary>
    /// IP地址
    /// </summary>
    public string IpAddress { get; set; }

    /// <summary>
    /// 异常严重程度
    /// </summary>
    public ExceptionSeverity Severity { get; set; }
}

/// <summary>
/// 异常日志详情模型
/// </summary>
public class ExceptionDetailDto : ExceptionItemDto
{
    /// <summary>
    /// 堆栈跟踪
    /// </summary>
    public string StackTrace { get; set; }

    /// <summary>
    /// 异常来源
    /// </summary>
    public string Source { get; set; }

    /// <summary>
    /// 跟踪ID
    /// </summary>
    public string TraceId { get; set; }

    /// <summary>
    /// 请求方法
    /// </summary>
    public string RequestMethod { get; set; }

    /// <summary>
    /// 日志级别
    /// </summary>
    public string Level { get; set; }

    /// <summary>
    /// 浏览器
    /// </summary>
    public string Browser { get; set; }

    /// <summary>
    /// 操作系统
    /// </summary>
    public string OS { get; set; }
}

/// <summary>
/// 异常统计模型
/// </summary>
public class ExceptionStatsDto
{
    /// <summary>
    /// 异常严重程度
    /// </summary>
    public ExceptionSeverity Severity { get; set; }

    /// <summary>
    /// 异常数量
    /// </summary>
    public int Count { get; set; }

    /// <summary>
    /// 统计日期
    /// </summary>
    public DateTime Date { get; set; }

    /// <summary>
    /// 租户ID
    /// </summary>
    public Guid? TenantId { get; set; }
}

/// <summary>
/// 异常日志统计前端显示DTO
/// </summary>
public class ExceptionStatsFrontendDto
{
    /// <summary>
    /// 统计日期，格式：yyyy-MM-dd
    /// </summary>
    public string Date { get; set; }

    /// <summary>
    /// 低级别异常数量
    /// </summary>
    public int Severity0Count { get; set; }

    /// <summary>
    /// 中级别异常数量
    /// </summary>
    public int Severity1Count { get; set; }

    /// <summary>
    /// 高级别异常数量
    /// </summary>
    public int Severity2Count { get; set; }

    /// <summary>
    /// 危险级别异常数量
    /// </summary>
    public int Severity3Count { get; set; }
}